package com.hb.core.pojo.project.order.dto;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.hb.core.pojo.Attachments;
import com.hb.core.pojo.JSONObjectProperty;
import com.hb.core.pojo.enums.FeeTypeEnum;
import com.hb.core.pojo.project.order.entity.UserOrder;
import com.hb.core.pojo.project.order.entity.UserOrderGoods;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.fzzn.core.model.enums.MsgEnum;
import org.fzzn.core.util.Enums;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * describe:
 * 订单信息的Dto
 *
 * @author zhongdl
 * @date 2021/09/29
 */
@Getter
@Setter
public class UserOrderDTO extends UserOrder {

    @ApiModelProperty(value = "收款方式ID")
    private Long collectionId;

    @ApiModelProperty(value = "标段ID")
    private Long sectionId;

    @ApiModelProperty(value = "招标文件ID")
    private Long fileId;

    @ApiModelProperty(value = "交易查询开始时间")
    @JsonFormat(shape= JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime payTimeStart;

    @ApiModelProperty(value = "项目名称")
    private String projectName;

    @ApiModelProperty(value = "代理公司")
    private String projectOrgName;

    @ApiModelProperty(value = "交易查询结束时间")
    @JsonFormat(shape= JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime  payTimeEnd;

    @ApiModelProperty(value = "数据来源")
    private String source;

    @ApiModelProperty(value = "商品列表")
    private List<UserOrderGoods> goods;

    /**
     * 创建订单参数验证方法
     *
     * @param fieldNames
     * @return
     */
    @Override
    public String paramsValid(String... fieldNames) {
        Integer feeType = getFeeType();
        if (feeType == null) {
            return "费用(商品)类型不能为空";
        }
        // 只有投标保证金需要添加退款方信息
        if (Enums.equals(FeeTypeEnum.BID_PRO, feeType)) {
            JSONObjectProperty refundInfo = getRefundInfo();
            if (CollUtil.isEmpty(refundInfo)) {
                return "退款方信息不能为空";
            }
            UserRefundDTO userRefundDTO = refundInfo.toBean(UserRefundDTO.class);
            String paramsValid = userRefundDTO.paramsValid();
            if (StrUtil.isNotEmpty(paramsValid)) {
                return paramsValid;
            }
        }
        if (getSectionId() == null) {
            return MsgEnum.INCORRECT_PARAM.msg();
        }
        // 付款凭证必传
        Attachments attachment = getAttachment();
        if (CollUtil.isEmpty(attachment)) {
            return MsgEnum.INCORRECT_PARAM.msg();
        }

        // 费用类型必填
        List<UserOrderGoods> goods = getGoods();
        if (CollUtil.isEmpty(goods)) {
            return "缺失商品信息";
        }
        return null;
    }

    /* 费用管理统计字段 start */
    private String sectionName;
    private String sectionCode;
    private Integer waitAudit;
    private Integer passed;
    private Integer reject;
    private Integer refund;
    private BigDecimal price;
    /* 费用管理统计字段 end */

    /* 查询字段 start */
    /**
     * 费用类型, 用于查询该类型的商品列表
     */
    private Integer feeType;
    /* 查询字段 end */


    @ApiModelProperty(value = "退款id集合")
    private List<Long> ids;
    @ApiModelProperty(value = "企业ID")
    private Long orgId;
}
